﻿using AllServer.Share;
using Furion.DependencyInjection;
using Grpc.Net.Client;
using MagicOnion.Client;

namespace AllServer.GrpcClient.Proxy
{    public interface IProxyGrpcClient
    {
        Task<bool> IsProxy(int memberId);

        Task<ProxyInfo> GetProxy(int memberId);
    }

    public class ProxyGrpcClient : IProxyGrpcClient, ITransient
    {
        public async Task<ProxyInfo> GetProxy(int memberId)
        {
            var channel = GrpcChannel.ForAddress("https://localhost:7221");
            var memberGrpc = MagicOnionClient.Create<IProxyGrpcService>(channel);
            return await memberGrpc.GetProxy(memberId);
        }

        public async Task<bool> IsProxy(int memberId)
        {
            var channel = GrpcChannel.ForAddress("https://localhost:7221");
            var memberGrpc = MagicOnionClient.Create<IProxyGrpcService>(channel);
            return await memberGrpc.IsProxy(1);
        }
    }
}
